package io.fredia.femicro.auth.server.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import io.fredia.femicro.auth.server.interceptor.ServiceAuthRestInterceptor;
import io.fredia.femicro.auth.server.interceptor.UserAuthRestInterceptor;
import io.fredia.femicro.common.handler.GlobalExceptionHandler;

/**
 * MVC配置
 * 
 * @author : Fredia
 * @since : 2018年3月16日
 * @version : v1.0.0
 */
@Configuration("admimWebConfig")
@Primary
public class WebConfiguration implements WebMvcConfigurer {
	@Bean
	GlobalExceptionHandler getGlobalExceptionHandler() {
		return new GlobalExceptionHandler();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(getServiceAuthRestInterceptor()).addPathPatterns("/service/**");
		registry.addInterceptor(getUserAuthRestInterceptor()).addPathPatterns("/service/**");
	}

	@Bean
	ServiceAuthRestInterceptor getServiceAuthRestInterceptor() {
		return new ServiceAuthRestInterceptor();
	}

	@Bean
	UserAuthRestInterceptor getUserAuthRestInterceptor() {
		return new UserAuthRestInterceptor();
	}

}
